<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2023/6/24
  Time: 8:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>报价单列表</title>
    <!-- 引入 layui.css -->
    <link href="//unpkg.com/layui@2.8.0/dist/css/layui.css" rel="stylesheet">
    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.8.0/dist/layui.js"></script>
</head>
<body>
<button type="button" id="id" name="search" class="layui-btn" onclick="searchByCond()" style="display: flex;margin-left: 85%;">搜索</button>
<form class="layui-form" action="form.html">
    <div class="layui-form-item">
        <div class="layui-inline" style="display: flex;justify-content: center;align-items: center;">
            <div class="layui-inline">
                <label class="layui-form-label">款号:</label>
                <div class="layui-input-inline layui-input-wrap">
                    <input type="text" name="styleNumber" lay-verify="required" placeholder="按照 款号 搜索"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">时间:</label>
                <div class="layui-input-inline layui-input-wrap">
                    <input type="text" name="brand" lay-verify="required" placeholder="按照 时间 搜索"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
    </div>
</form>
<table id="demo" lay-filter="demo"></table>
</body>
<script type="text/javascript/" id="barDemo">
    <button class="layui-btn layui-btn-danger layui-btn-sm layui-btn-disabled" id="barDemo"  lay-event="deleteProduct" onclick="aa()">审核</button>
</script>
<script type="text/javascript/" id="barDemo1">
    <button class="layui-btn layui-btn-danger layui-btn-sm" id="1barDemo"  lay-event="deleteProduct" onclick="aa()">未审核</button>
</script>
<%--查询全部--%>
<script>
    // layui.use(function () {
    //     var element = layui.element;
    //     var layer = layui.layer;
    //     // 折叠面板点击事件
    //     element.on('collapse(filter-collapse)', function (data) {
    //         console.log(data.show); // 得到当前面板的展开状态，true or false
    //         console.log(data.title); // 得到当前点击面板的标题区域对象
    //         console.log(data.content); // 得到当前点击面板的内容区域对象
    //     });
    // });
    layui.use('table', function () {
        var table = layui.table;
        // 创建渲染实例
        table.render({
            elem: '#demo'
            , url: 'quotationManager/getAllQuotation' // 此处为静态模拟数据，实际使用时需换成真实接口
            , height: 480 // 最大高度减去其他容器已占有的高度差
            , page: true
            , cols: [[
                {field: 'styleNumberId', title: '款号编号'}
                ,{field: 'styleNumber', title: '款号'}
                , {field: 'brand', title: '品牌'}
                , {field: 'predictReorder', title: '预计返单(件)'}
                , {field: 'productionCycle', title: '生产周期(天)'}
                , {field: 'clothStore', title: '面料储备',templet:function (b) {
                        if (b.clothStore=="0"){
                            return "有";
                        } else if (b.clothStore =="1"){
                            return"无";
                        }
                    }}
                , {field: 'factoryName', title: '生产部门'}
                , {field: 'factoryPrincipal', title: '负责人'}
                , {field: 'tax', title: '系数'}
                , {field: 'totalFee', title: '成本'}
                , {field: 'costWithTax', title: '含税价'}
                , {field: 'createTime', title: '提交时间'}
                , {field: 'auditStatus', title: '审核状态',templet:function (m) {
                        if (m.auditStatus =="0"){
                            return"未审核"
                        } else if (m.auditStatus=="1"){
                            return"已提交审核"
                        }else if (m.auditStatus=="2") {
                            return"审核已完成"
                        }
                    }}
                , {field: '', title: '操作', width: 140,templet: function (m) {
                        // alert(d.auditStatus )
                        if (m.auditStatus =="1") {
                            return '<button class="layui-btn layui-btn-danger layui-btn-sm layui-btn-disabled" id="barDemo"  lay-event="deleteProduct">已提交审核</button>\n';
                        } else if (m.auditStatus =="0") {
                            return '<button class="layui-btn layui-btn-danger layui-btn-sm" id="1barDemo"  lay-event="deleteProduct">审核</button>';
                        }
                    }}
            ]]
        })
    })


    layui.use('table', function() {
        var table = layui.table;
        // 监听表格工具栏按钮的点击事件
        table.on('tool(demo)', function(obj) {
            var data = obj.data; // 获得当前行数据
            if (obj.event === 'deleteProduct') {
                var styleNumberId = data.styleNumberId; // 提取订单ID
                alert(styleNumberId); // 显示订单ID
                $.ajax({
                    url: 'quotationManager/changeAuditStatus',
                    type: 'GET',
                    data: {styleNumberId: styleNumberId},
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    success: function(result) {
                        if (result ==1) {
                            // 修改按钮文本为"已提交审核"
                            var btnElem = $(obj.tr).find('.layui-btn');
                            btnElem.text('已提交审核');
                            btnElem.removeClass('layui-btn-danger').addClass('layui-btn-disabled');
                            btnElem.attr('disabled', 'disabled');
                            table.render({
                                elem: '#demo'
                                , url: 'quotationManager/getAllQuotation' // 此处为静态模拟数据，实际使用时需换成真实接口
                                , height: 480 // 最大高度减去其他容器已占有的高度差
                                , page: true
                                , cols: [[
                                    {field: 'styleNumberId', title: '款号编号'}
                                    ,{field: 'styleNumber', title: '款号'}
                                    , {field: 'brand', title: '品牌'}
                                    , {field: 'predictReorder', title: '预计返单(件)'}
                                    , {field: 'productionCycle', title: '生产周期(天)'}
                                    , {field: 'clothStore', title: '面料储备',templet:function (b) {
                                            if (b.clothStore=="0"){
                                                return "有";
                                            } else if (b.clothStore =="1"){
                                                return"无";
                                            }
                                        }}
                                    , {field: 'factoryName', title: '生产部门'}
                                    , {field: 'factoryPrincipal', title: '负责人'}
                                    , {field: 'tax', title: '系数'}
                                    , {field: 'totalFee', title: '成本'}
                                    , {field: 'costWithTax', title: '含税价'}
                                    , {field: 'createTime', title: '提交时间'}
                                    , {field: 'auditStatus', title: '审核状态',templet:function (m) {
                                            if (m.auditStatus =="0"){
                                                return"未审核"
                                            } else if (m.auditStatus=="1"){
                                                return"已提交审核"
                                            }else if (m.auditStatus=="2") {
                                                return"审核已完成"
                                            }
                                        }}
                                    , {field: '', title: '操作', width: 140,templet: function (m) {
                                            // alert(d.auditStatus )
                                            if (m.auditStatus =="1") {
                                                return '<button class="layui-btn layui-btn-danger layui-btn-sm layui-btn-disabled" id="barDemo"  lay-event="deleteProduct">已提交审核</button>\n';
                                            } else if (m.auditStatus =="0") {
                                                return '<button class="layui-btn layui-btn-danger layui-btn-sm" id="1barDemo"  lay-event="deleteProduct">审核</button>';
                                            }
                                        }}
                                ]]
                            })
                        } else {
                            alert("已审核过了");
                        }
                    },
                    error: function(jqXHR, textStatus, errorThrown) {
                        alert('请求失败，错误信息：' + errorThrown);
                    }
                });

            }

        });
    });
</script>
<%--条件查询--%>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
    function searchByCond(){
        let styleNumber = $('[name=styleNumber]').val();

        alert(styleNumber);
        $.ajax( {
            "url"            :  "quotationManager/getQuotationListByCond",                      // 要提交的URL路径
            "type"         :  "post",                     // 发送请求的方式
            "data"         :  {styleNumber:styleNumber},                      // 要发送到服务器的数据
            "dataType" :  "json",                   // 期望接受的数据格式
        /*    "contentType":"application/json;charset=utf-8;",*/
            "success"  :  function(result) {  // 请求成功后要执行的代码
                // console.log(result);
                    $('#demo').empty();

                    layui.use('table', function () {
                        var table = layui.table;
                        // 创建渲染实例
                        table.render({
                            elem: '#demo'
                            , url: 'quotationManager/getAllQuotation' // 此处为静态模拟数据，实际使用时需换成真实接口
                            , height: 480 // 最大高度减去其他容器已占有的高度差
                            , page: true
                            , cols: [[
                                {field: 'styleNumberId', title: '款号编号'}
                                ,{field: 'styleNumber', title: '款号'}
                                , {field: 'brand', title: '品牌'}
                                , {field: 'predictReorder', title: '预计返单(件)'}
                                , {field: 'productionCycle', title: '生产周期(天)'}
                                , {field: 'clothStore', title: '面料储备',templet:function (b) {
                                        if (b.clothStore=="0"){
                                            return "有";
                                        } else if (b.clothStore =="1"){
                                            return"无";
                                        }
                                    }}
                                , {field: 'factoryName', title: '生产部门'}
                                , {field: 'factoryPrincipal', title: '负责人'}
                                , {field: 'tax', title: '系数'}
                                , {field: 'totalFee', title: '成本'}
                                , {field: 'costWithTax', title: '含税价'}
                                , {field: 'createTime', title: '提交时间'}
                                , {field: 'auditStatus', title: '审核状态',templet:function (m) {
                                        if (m.auditStatus =="0"){
                                            return"未审核"
                                        } else if (m.auditStatus=="1"){
                                            return"已提交审核"
                                        }else if (m.auditStatus=="2") {
                                            return"审核已完成"
                                        }
                                    }}
                                , {field: '', title: '操作', width: 140,templet: function (m) {
                                        // alert(d.auditStatus )
                                        if (m.auditStatus =="1") {
                                            return '<button class="layui-btn layui-btn-danger layui-btn-sm layui-btn-disabled" id="barDemo"  lay-event="deleteProduct">已提交审核</button>\n';
                                        } else if (m.auditStatus =="0") {
                                            return '<button class="layui-btn layui-btn-danger layui-btn-sm" id="1barDemo"  lay-event="deleteProduct">审核</button>';
                                        }
                                    }}
                            ]]
                        })
                    })

                    // window.location.href="tosearch";

            },
            "error"       :  function() {           // 请求失败后要执行的代码
                alert("条件查询出错了！")
            }
        } );

    }
</script>
</body>
</html>